
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<!-- <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> -->
	<title>Document</title>

	<link href="dhtmlxchart_1.css" rel="stylesheet" type="text/css">
	<link href="global2_v20150401094815.css" rel="stylesheet" type="text/css">
	<link href="wea_local2_v20150410140642.css" rel="stylesheet" type="text/css">
</head>
<body>
	<?php
	// header('Content-type:text/html;charset=UTF-8');
	// 抓取页面
	@$weatherWebCont =file_get_contents('http://tianqi.2345.com/beijing/54511.htm');
	// $weatherWebCont = file_get_contents('http://tianqi.2345.com/beijing/54511.htm', false, '获取天气失败');
	// var_dump($weatherWebCont);
	if($weatherWebCont){
		$weatherWebCont=$weatherWebCont;
	}else{
		$weatherWebCont='未获取天气';
		// echo $weatherWebCont;
	}

	// 去除空格
	$cont = str_ireplace(' ', '', $weatherWebCont); 
	// 查询需要内容开始 位置
	// echo strpos($cont,'<divclass="city_t">');   //9314
	// echo strpos($cont,'<divclass="hotwords">');  //15635
	$cont = substr($cont,9314,15635-9314);   //缩小范围处理内容  截取未来15天天气预报块
	// var_dump($cont);
	// echo $cont;


	// 抓取今天天气
	// 获取开始位置 
	// echo strpos($cont,'<fontclass="gray">');   //2366 
	// 获取结束位置 
	// echo strpos($cont,'<fontclass="blue">');  //2446 
	$dayNight = substr($cont,2366,2446-2366);  //白天夜间天气
	// echo $dayNight; //白天：晴夜间：晴
	// 进行替换

	// echo  str_replace(array('白天','夜间'),'',$dayNight);

	// echo $dayNight;


	// 先转码再替换中文  
	// $daystr = urlencode('白天：');
	// $nightstr = urlencode('夜间：');
	// $dayNight = urlencode($dayNight);
	// 	echo urldecode($nightstr);
	// $dayNight = str_replace($daystr,'',$dayNight);
	// echo '<br />'.urldecode($nightstr);
	
	

	// 温度获取
	$low = substr($cont,2446 ); //2446 
	$temperature = substr($low,1,49); //
	$temperature = str_replace('fontclass="blue">', '', $temperature);
	// echo $temperature; //10～25℃ 

$today = $dayNight . $temperature;
$today = str_ireplace(array('<fontclass="gray">','</font>','</b>','<i>','<b>','<fontclass="red">'),'', $today);
$today = iconv('GB2312', 'UTF-8', $today);
// echo $today;
// file_put_contents('weahter.php',$today);
// $today = strip_tags($today);

// 存入数据库
 echo $today;
	// $today =var_export($today,true);
/*	// file_put_contents('./weahter.php',"<?php \r\n return " .$today ."\r\n?>"); */



	if($today){
		$today =$today;
    }else{
		$today ='无天气信息';
    }


	?>
</body>
</html>